using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using WebControls;
using System.IO;

public partial class Utils_FileBrowser : SFPage
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            FillRepeater();
        }
    }
    protected override void OnPreInit(EventArgs e)
    {
        
    }
    private void FillRepeater()
    {
        DataTable insDataTableFiles = new DataTable();
        insDataTableFiles.Columns.Add("FilePath", typeof(string));
        insDataTableFiles.Columns.Add("FileName", typeof(string));
        insDataTableFiles.Columns.Add("Size", typeof(string));
        foreach (string s in Directory.GetFiles(Server.MapPath(Request.QueryString["Path"])))
        {
            FileInfo f = new FileInfo(s);


                long kb = f.Length / 1024;
                insDataTableFiles.Rows.Add(new object[] { Request.QueryString["Path"] + s.Replace(Server.MapPath(Request.QueryString["Path"]), ""), s.Replace(Server.MapPath(Request.QueryString["Path"]), ""), kb.ToString() });
                LinkButton lbt = new LinkButton();
       
        }
        rptFiles.DataSource = insDataTableFiles;
        rptFiles.DataBind();
    }
    protected string GenerateOnclick(object fileName, object filePath, object size)
    {
        return @"window.returnValue=this.href + '|" + fileName.ToString() + "|" + size + "';window.close();return false;";
    }
    protected void btnUpload_Click(object sender, EventArgs e)
    {
        if (flUpload.PostedFile.FileName != "")
        {
            if (File.Exists(System.Web.HttpContext.Current.Server.MapPath(System.Web.HttpUtility.UrlDecode(Request.QueryString["Path"])) + flUpload.FileName))
            {
                this.Page.ClientScript.RegisterStartupScript(this.GetType(), "fileExists", "alert('" + StaticMethods.GetErrorMessageMultilanguageString(11, new object[] { }) + "')", true);
                return;
            }
            flUpload.SaveAs(System.Web.HttpContext.Current.Server.MapPath(System.Web.HttpUtility.UrlDecode(Request.QueryString["Path"])) +  flUpload.FileName);
            FillRepeater();
        }
    }
}
